package hotel.switchs.oversea.online.controller;

import hotel.base.oversea.entity.SwitchPriceBaseSetEntity;
import hotel.base.oversea.utils.JSONUtils;
import hotel.base.oversea.utils.Result;
import hotel.switchs.oversea.online.service.SwitchPriceBaseSetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 酒店上架价格设置
 * @Author lmf
 * @Date 2020/6/10 13:39
 **/
@Slf4j
@RestController
@RequestMapping("/switchPriceBaseSet")
@Api(value = "SwitchPriceBaseSetController",tags = {"酒店上架价格设置"})
public class SwitchPriceBaseSetController {
    @Autowired
    private SwitchPriceBaseSetService switchPriceBaseSetService;

    @PostMapping("/addPriceBaseSet")
    @ApiOperation(value = "添加酒店上架价格设置",notes="必须经过auth授权")
    public Result<Object> addPriceBaseSet(@RequestBody SwitchPriceBaseSetEntity switchPriceBaseSetEntity){
        return switchPriceBaseSetService.addPriceBaseSet(switchPriceBaseSetEntity);
    }

    @GetMapping("/getPriceList")
    @ApiOperation(value = "获取酒店酒店上架价格设置",notes="必须经过auth授权")
    public Result<Object> getPriceList(){
        return switchPriceBaseSetService.getPriceList();
    }
    @GetMapping("/deletePriceListById")
    @ApiOperation(value = "删除酒店上架价格设置",notes="必须经过auth授权")
    public Result<Object> deletePriceListById(@RequestParam("id")int id){
        return switchPriceBaseSetService.deletePriceListById(id);
    }
    @PostMapping("/updatePriceListById")
    @ApiOperation(value = "更新酒店上架价格设置",notes="必须经过auth授权")
    public Result<Object> updatePriceListById(@RequestBody SwitchPriceBaseSetEntity switchPriceBaseSetEntity){
        log.info("=============switchPriceBaseSetEntity的数据为{}=====", JSONUtils.toJSONString(switchPriceBaseSetEntity));
        return switchPriceBaseSetService.updatePriceListById(switchPriceBaseSetEntity);
    }
    /***
    * @Author: lmf
    * @Date: 2021/3/4
     *设置价格公式分割时间
    */
    @PostMapping("/setPriceTimeToCache")
    @ApiOperation(value = "设置价格公式分割时间",notes = "必须经过auth授权")
    public Result<Object> setPriceTimeToCache(@RequestBody Map<String,Integer> params){
        Integer hour=params.get("hour");
        return switchPriceBaseSetService.setPriceTimeToCache(hour);
    }

    /***
    * @Author: lmf
    * @Date: 2021/3/4
     * 控制酒店是否执行自已的价格公式
    */
    @PostMapping("/setOpenHotelPriceToCache")
    @ApiOperation(value = "设置价格公式分割时间",notes = "必须经过auth授权")
    public Result<Object> setOpenHotelPriceToCache(@RequestBody Map<String,Integer> params){
        Integer open=params.get("open");
        return switchPriceBaseSetService.setOpenHotelPriceToCache(open);
    }

    /****
    * @Author: lmf
    * @Date: 2021/3/8
     * 根据酒店id获取使用的价格公式
    */
    @PostMapping("/getPriceRelationList")
    @ApiOperation(value = "根据酒店id获取使用的价格公式",notes = "必须经过auth授权")
    public Result<Object> getPriceRelationList(@RequestBody Map<String,Integer> params){
        Integer hotelId=params.get("hotelId");
        return switchPriceBaseSetService.getPriceRelationList(hotelId);
    }
}
